package com.mobzilla.activity;

import java.util.List;

import com.mobzilla.model.User;
import com.mobzilla.service.ServiceFactory;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class LoadActivity  extends Activity
{
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		
		super.onCreate(savedInstanceState);		
		setContentView(R.layout.loadbalance);
		
		TextView mb = (TextView) findViewById(R.id.mostBusy);
		TextView lb = (TextView) findViewById(R.id.leastBusy);
		
		mb.setClickable(true);
		lb.setClickable(true);
		

		mb.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v) {
				List<User> usersList = ServiceFactory.getLoadBalancerInstance().getTopUsersFromList(5);
				String[] names = new String[usersList.size()];
				for(int i=0; i< usersList.size(); i++)
				{
					names[i]= new String("User : " + usersList.get(i).getName() + ", Defect count :" + usersList.get(i).getId());
				}
				//String names[] = new String[] {"qwe","wer","rty","tyu","uio"};
				NameListActivity.setParam("Most Busy", names);
				Intent i = new Intent(LoadActivity.this, NameListActivity.class);
				LoadActivity.this.startActivity(i);				
			}
		});
		
		lb.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				List<User> usersList = ServiceFactory.getLoadBalancerInstance().getWorstUsersFromList(5);
				String[] names = new String[usersList.size()];
				for(int i=0; i< usersList.size(); i++)
				{
					names[i]= new String("User : " + usersList.get(i).getName() + ", Defect count :" + usersList.get(i).getId());
				}
				//String names[] = new String[] {"qwe","wer","rty","tyu","uio"};
				NameListActivity.setParam("Least Busy", names);
				Intent i = new Intent(LoadActivity.this, NameListActivity.class);
				LoadActivity.this.startActivity(i);				
			}
		});
			
		Button backButton = (Button) findViewById(R.id.loadBackButton);
		backButton.setOnClickListener(new MyBackButtonListener2(this));
	}
}

class MyBackButtonListener2 implements OnClickListener
{
	private Activity activity;
	
	public MyBackButtonListener2(Activity a)
	{
		this.activity = a;
	}
	
	public void onClick(View v)
	{
		activity.finish();
	}
}
